<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/common.css" media="all">
    <script src="/js/layui/layui.all.js"></script>
    <script src="/admin/js/token.js"></script>
</head>
<style type="text/css">
    .label {
        width: 160px;
        padding: 0px;
    }

    .div {
        margin-left: 170px;

    }

    .formbox {
        height: 1px;
    }

    body {
        background-color: white;
    }
</style>

<body>
<div class="layui-row">
    <div class="layui-col-md3  formbox ">
    </div>

    <div class="layui-fluid layui-col-md6 layui-col-sm12 ">
        <div class="layui-card">
            <div class="layui-card-body" style="padding: 15px;" class="layui-row">

                <form class="layui-form">
                    <div class="layui-form-item">
                        <label class="layui-form-label label">apk上传：</label>
                        <div class="layui-input-block div">
                            <a class="layui-btn" id="upFile"><i class="layui-icon layui-icon-upload"></i>预览</a>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label label">系统应用名称：</label>
                        <div class="layui-input-block div">
                            <input type="text" name="title" id="systemApkName" required lay-verify="required" autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label label">系统应用包名：</label>
                        <div class="layui-input-block div">
                            <input type="text" name="title" id="systemApkPackageName" required lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label label">系统应用版本：</label>
                        <div class="layui-input-block div">
                            <input type="text" name="title" id="systemApkVesion" required lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label label">系统应用版本名称：</label>
                        <div class="layui-input-block div">
                            <input type="text" name="title" id="systemApkVersionName" required lay-verify="required" autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label label">系统应用版本更改内容：</label>
                        <div class="layui-input-block div">
                            <textarea name="desc" id="systemApkVesionText" class="layui-textarea"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label label">是否启用升级：</label>
                        <div class="layui-input-block div">
                            <select name="city" id="systemApkStatus">
                                <option value="否">否</option>
                                <option value="是">是</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-form-item layui-layout-admin">
                        <div class="layui-input-block">
                            <div class="layui-footer" style="left: 0">
                                <button class="layui-btn layui-icon layui-icon-add-edit" lay-submit lay-filter="update"
                                        id="add">修改
                                </button>
                                <button class="layui-btn layui-icon layui-icon-close" id="back">
                                    取消
                                </button>
                            </div>
                        </div>
                    </div>

                </form>
            </div>
            <div class="layui-col-md3 formbox">
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    //表单
        //进度条
        var element = layui.element;
        //表单
        var form = layui.form;
        //上传
        var upload = layui.upload;
        //文件
        var systemApkFile = null;
        //取值
        var s = layui.data("s");
        $("#systemApkName").val(s.systemapk.systemApkName);
        $("#systemApkPackageName").val(s.systemapk.systemApkPackageName);
        $("#systemApkVesion").val(s.systemapk.systemApkVesion);
        $("#systemApkVersionName").val(s.systemapk.systemApkVersionName);
        $("#systemApkVesionText").val(s.systemapk.systemApkVesionText);
        $("#systemApkStatus").val(s.systemapk.systemApkStatus);
        form.render();


        form.on('submit(update)', function () {

            if(systemApkFile == null)
            {
                layer.msg('请先选择上传的apk文件', {
                    icon: 7
                })
                return false;
            }
            $.ajax({
                type: 'post',
                url: '/admin/system-apk/updateSystemApkById',
                data: {
                    systemApkId: s.systemapk.systemApkId,
                    systemApkName: $("#systemApkName").val(),
                    systemApkPackageName: $("#systemApkPackageName").val(),
                    systemApkVesion: $("#systemApkVesion").val(),
                    systemApkVersionName: $("#systemApkVersionName").val(),
                    systemApkVesionText: $("#systemApkVesionText").val(),
                    systemApkStatus: $("#systemApkStatus").val(),
                    systemApkPackageName:package,
                    systemApkVesion:versionCode,
                    systemApkVersionName:versionName,
                    systemApkMd5:MD5,
                    systemApkUrl:filePath,
                },
                success: function (res) {
                    if (res.code == 200) {
                        layer.msg('编辑成功', {icon: 1});
                        setTimeout(function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }, 1000);
                        return;
                    }
                    if(res.code==500) {
                        layer.msg(res.data, {
                            icon: 2
                        })
                    }
                },
                error: function (res) {
                    layer.msg('服务器错误或网咯异常', {icon: 2});
                }
            });
            return false;
        })

        $('#back').click(function () {
            var index = parent.layer.getFrameIndex(window.name) //获取窗口索引
            parent.layer.close(index)    //关闭弹出层
        })

        //文件上传
        upload.render({
            elem: '#upFile',
            url: '/admin/fileinfo/upload/image',
            exts:'apk',
            size:1024*100,
            accept: 'file', //普通文件
            progress:function(value){//上传进度回调 value进度值
                element.progress('demo', value+'%')//设置页面进度条
            },
            choose: function (obj) {
                systemApkFile = null;
                //预览
                obj.preview(function (index, file, result) {
                })
            },
            done: function (res,index, upload) { //上传完成
                layer.msg('上传成功',{
                    icon:1,
                    time:800
                });
                systemApkFile=res.data.package;
                package=res.data.package;
                versionName=res.data.versionName;
                versionCode=res.data.versionCode;
                MD5=res.data.MD5;
                filePath=res.data.filePath;
                uploadTime=res.data.uploadTime;
                $("#systemApkPackageName").val(systemApkFile);
                $('#systemApkVesion').val(versionCode);
                $('#systemApkVersionName').val(versionName);
            }
        });
</script>

</html>